package com.zlm.user.partner.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.dto.userPartner.SysPartnerDto;
import com.zlm.user.partner.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 登录合伙人controller-（内部服务）
 * @Author: duyufu
 * @Date: 2019/7/10 13:31
 */
@RestController
@RequestMapping("/loginPartner")
public class LoginController extends BaseController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     * @param mobile
     * @return
     */
    @GetMapping("/loginPartner")
    public JsonResultDto loginPartner(String mobile) {
        try {
            SysPartnerDto login = loginService.loginPartner(mobile);
            return success(login);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 验证码注册登录
     * @param mobile
     * @return
     */
    @GetMapping("/activationLogin")
    public JsonResultDto activationLogin(String mobile) {
        try {
            SysPartnerDto login = loginService.activationLogin(mobile);
            return success(login);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 环信注册
     * @param userId
     * @return
     */
    @GetMapping(value = "/huanxinRegister")
    public JsonResultDto huanxinRegister(Integer userId) {
        try {
            loginService.huanxinRegister(userId);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 强制下线
     * @param userHxId
     * @return
     */
    @GetMapping(value = "/huanxinDisconnect")
    public JsonResultDto huanxinDisconnect(String userHxId) {
        try {
            loginService.huanxinDisconnect(userHxId);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }



}
